<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: NotificationBoard Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00164.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-types">Public Types</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#pro-attribs">Protected Attributes</a> &#124;
<a href="#friends">Friends</a>  </div>
  <div class="headertitle">
<div class="title">NotificationBoard Class Reference</div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="NotificationBoard" -->
<p><code>#include &lt;<a class="el" href="a00328_source.html">NotificationBoard.h</a>&gt;</code></p>

<p><a href="a00915.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-types"></a>
Public Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aaf7daab1d6f01c2993bc3676e1220281"></a><!-- doxytag: member="NotificationBoard::NotifiableVector" ref="aaf7daab1d6f01c2993bc3676e1220281" args="" -->
typedef std::vector<br class="typebreak"/>
&lt; <a class="el" href="a00102.html">INotifiable</a> * &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>NotifiableVector</b></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a04c2b90ab6db51c359ace8d11caf4041"></a><!-- doxytag: member="NotificationBoard::ClientMap" ref="a04c2b90ab6db51c359ace8d11caf4041" args="" -->
typedef std::map&lt; int, <br class="typebreak"/>
NotifiableVector &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>ClientMap</b></td></tr>
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td colspan="2"><div class="groupHeader">Methods for consumers of change notifications</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00164.html#aeb02a282e6c807c1cb064a28e8409ff2">subscribe</a> (<a class="el" href="a00102.html">INotifiable</a> *client, int category)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00164.html#a618069a9c5e40e5adc663def23325035">unsubscribe</a> (<a class="el" href="a00102.html">INotifiable</a> *client, int category)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00164.html#a668821c8867857ed47a4adaaa99248f8">hasSubscribers</a> (int category)</td></tr>
<tr><td colspan="2"><div class="groupHeader">Methods for producers of change notifications</div></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification</a> (int category, const cObject *details=NULL)</td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00164.html#a3f958d3beda02f0a0ad5672bbed4f953">initialize</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00164.html#a95125026311c1ebea679364a6eb6d4a3">handleMessage</a> (cMessage *msg)</td></tr>
<tr><td colspan="2"><h2><a name="pro-attribs"></a>
Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="acb59aab805c7544f4a9800a2498cc828"></a><!-- doxytag: member="NotificationBoard::clientMap" ref="acb59aab805c7544f4a9800a2498cc828" args="" -->
ClientMap&#160;</td><td class="memItemRight" valign="bottom"><b>clientMap</b></td></tr>
<tr><td colspan="2"><h2><a name="friends"></a>
Friends</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a4dc63b8b48b2e35f9fa899c3525310f6"></a><!-- doxytag: member="NotificationBoard::operator&lt;&lt;" ref="a4dc63b8b48b2e35f9fa899c3525310f6" args="(std::ostream &amp;, const NotifiableVector &amp;)" -->
std::ostream &amp;&#160;</td><td class="memItemRight" valign="bottom"><b>operator&lt;&lt;</b> (std::ostream &amp;, const NotifiableVector &amp;)</td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Acts as a intermediary between module where state changes can occur and modules which are interested in learning about those changes; "Notification Broker".</p>
<p>Notification events are grouped into "categories." Examples of categories are: NF_RADIOSTATE_CHANGED, NF_PP_TX_BEGIN, NF_PP_TX_END, NF_IPv4_ROUTE_ADDED, NF_BEACON_LOST, NF_NODE_FAILURE, NF_NODE_RECOVERY, etc. Each category is identified by an integer (right now it's assigned in the source code via an enum, in the future we'll convert to dynamic category registration).</p>
<p>To trigger a notification, the client must obtain a pointer to the <a class="el" href="a00164.html">NotificationBoard</a> of the given host or router (explained later), and call its <a class="el" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification()</a> method. The notification will be delivered to all subscribed clients immediately, inside the <a class="el" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification()</a> call.</p>
<p>Clients that wish to receive notifications should implement (subclass from) the <a class="el" href="a00102.html">INotifiable</a> interface, obtain a pointer to the <a class="el" href="a00164.html">NotificationBoard</a>, and subscribe to the categories they are interested in by calling the <a class="el" href="a00164.html#aeb02a282e6c807c1cb064a28e8409ff2">subscribe()</a> method of the <a class="el" href="a00164.html">NotificationBoard</a>. Notifications will be delivered to the receiveChangeNotification() method of the client (redefined from <a class="el" href="a00102.html">INotifiable</a>).</p>
<p>In cases when the category itself (an int) does not carry enough information about the notification event, one can pass additional information in a data class. There is no restriction on what the data class may contain, except that it has to be subclassed from cObject, and of course producers and consumers of notifications should agree on its contents. If no extra info is needed, one can pass a NULL pointer in the <a class="el" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification()</a> method.</p>
<p>A module which implements <a class="el" href="a00102.html">INotifiable</a> looks like this:</p>
<pre>
 class Foo : public cSimpleModule, public <a class="el" href="a00102.html">INotifiable</a> {
     ...
     virtual void receiveChangeNotification(int category, const cObject *details) {..}
     ...
 };
 </pre><p>Obtaining a pointer to the <a class="el" href="a00164.html">NotificationBoard</a> module of that host/router:</p>
<pre>
 <a class="el" href="a00164.html">NotificationBoard</a> *nb; // this is best made a module class member
 nb = NotificationBoardAccess().get();  // best done in <a class="el" href="a00164.html#a3f958d3beda02f0a0ad5672bbed4f953">initialize()</a>
 </pre><p>See NED file for additional info.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="a00102.html">INotifiable</a> </dd></dl>
<dl class="author"><dt><b>Author:</b></dt><dd>Andras Varga </dd></dl>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a903a21cc32b9b3c8589765b86a767f8e"></a><!-- doxytag: member="NotificationBoard::fireChangeNotification" ref="a903a21cc32b9b3c8589765b86a767f8e" args="(int category, const cObject *details=NULL)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void NotificationBoard::fireChangeNotification </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>category</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const cObject *&#160;</td>
          <td class="paramname"><em>details</em> = <code>NULL</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Tells <a class="el" href="a00164.html">NotificationBoard</a> that a change of the given category has taken place. The optional details object may carry more specific information about the change (e.g. exact location, specific attribute that changed, old value, new value, etc). </p>

<p>Referenced by <a class="el" href="a00106.html#af43ca2b4f54392ce974effc35dcf72d1">InterfaceTable::addInterface()</a>, <a class="el" href="a00106.html#a59bf4ac426a9fd86c5ce4cb2c9fcc16e">InterfaceTable::deleteInterface()</a>, <a class="el" href="a00164.html#aeb02a282e6c807c1cb064a28e8409ff2">subscribe()</a>, and <a class="el" href="a00164.html#a618069a9c5e40e5adc663def23325035">unsubscribe()</a>.</p>
<div class="fragment"><pre class="fragment">{
    Enter_Method(<span class="stringliteral">&quot;fireChangeNotification(%s, %s)&quot;</span>, notificationCategoryName(category),
                 details?details-&gt;info().c_str() : <span class="stringliteral">&quot;n/a&quot;</span>);

    ClientMap::iterator it = clientMap.find(category);
    <span class="keywordflow">if</span> (it==clientMap.end())
        <span class="keywordflow">return</span>;
    NotifiableVector&amp; clients = it-&gt;second;
    <span class="keywordflow">for</span> (NotifiableVector::iterator j=clients.begin(); j!=clients.end(); j++)
        (*j)-&gt;receiveChangeNotification(category, details);
}
</pre></div>
</div>
</div>
<a class="anchor" id="a95125026311c1ebea679364a6eb6d4a3"></a><!-- doxytag: member="NotificationBoard::handleMessage" ref="a95125026311c1ebea679364a6eb6d4a3" args="(cMessage *msg)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void NotificationBoard::handleMessage </td>
          <td>(</td>
          <td class="paramtype">cMessage *&#160;</td>
          <td class="paramname"><em>msg</em></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Does nothing. </p>
<div class="fragment"><pre class="fragment">{
    error(<span class="stringliteral">&quot;NotificationBoard doesn&#39;t handle messages, it can be accessed via direct method calls&quot;</span>);
}
</pre></div>
</div>
</div>
<a class="anchor" id="a668821c8867857ed47a4adaaa99248f8"></a><!-- doxytag: member="NotificationBoard::hasSubscribers" ref="a668821c8867857ed47a4adaaa99248f8" args="(int category)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool NotificationBoard::hasSubscribers </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>category</em></td><td>)</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Returns true if any client has subscribed to the given category. This, by using a local boolean 'hasSubscriber' flag, allows performance-critical clients to leave out calls to <a class="el" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification()</a> if there's no one subscribed anyway. The flag should be refreshed on each NF_SUBSCRIBERLIST_CHANGED notification. </p>
<div class="fragment"><pre class="fragment">{
    ClientMap::iterator it = clientMap.find(category);
    <span class="keywordflow">return</span> it!=clientMap.end() &amp;&amp; !it-&gt;second.empty();
}
</pre></div>
</div>
</div>
<a class="anchor" id="a3f958d3beda02f0a0ad5672bbed4f953"></a><!-- doxytag: member="NotificationBoard::initialize" ref="a3f958d3beda02f0a0ad5672bbed4f953" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void NotificationBoard::initialize </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td><code> [protected, virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Initialize. </p>
<div class="fragment"><pre class="fragment">{
    WATCH_MAP(clientMap);
}
</pre></div>
</div>
</div>
<a class="anchor" id="aeb02a282e6c807c1cb064a28e8409ff2"></a><!-- doxytag: member="NotificationBoard::subscribe" ref="aeb02a282e6c807c1cb064a28e8409ff2" args="(INotifiable *client, int category)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void NotificationBoard::subscribe </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="a00102.html">INotifiable</a> *&#160;</td>
          <td class="paramname"><em>client</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>category</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Subscribe to changes of the given category </p>

<p>References <a class="el" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification()</a>.</p>
<div class="fragment"><pre class="fragment">{
    Enter_Method(<span class="stringliteral">&quot;subscribe(%s)&quot;</span>, notificationCategoryName(category));

    <span class="comment">// find or create entry for this category</span>
    NotifiableVector&amp; clients = clientMap[category];

    <span class="comment">// add client if not already there</span>
    <span class="keywordflow">if</span> (std::find(clients.begin(), clients.end(), client) == clients.end())
        clients.push_back(client);

    <a class="code" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification</a>(NF_SUBSCRIBERLIST_CHANGED, NULL);
}
</pre></div>
</div>
</div>
<a class="anchor" id="a618069a9c5e40e5adc663def23325035"></a><!-- doxytag: member="NotificationBoard::unsubscribe" ref="a618069a9c5e40e5adc663def23325035" args="(INotifiable *client, int category)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void NotificationBoard::unsubscribe </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="a00102.html">INotifiable</a> *&#160;</td>
          <td class="paramname"><em>client</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>category</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Unsubscribe from changes of the given category </p>

<p>References <a class="el" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification()</a>.</p>
<div class="fragment"><pre class="fragment">{
    Enter_Method(<span class="stringliteral">&quot;unsubscribe(%s)&quot;</span>, notificationCategoryName(category));

    <span class="comment">// find (or create) entry for this category</span>
    NotifiableVector&amp; clients = clientMap[category];

    <span class="comment">// remove client if there</span>
    NotifiableVector::iterator it = std::find(clients.begin(), clients.end(), client);
    <span class="keywordflow">if</span> (it!=clients.end())
        clients.erase(it);

    <a class="code" href="a00164.html#a903a21cc32b9b3c8589765b86a767f8e">fireChangeNotification</a>(NF_SUBSCRIBERLIST_CHANGED, NULL);
}
</pre></div>
</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Projects/MiXiM/extsrc/mixim/src/inet_stub/base/<a class="el" href="a00328_source.html">NotificationBoard.h</a></li>
<li>D:/Projects/MiXiM/extsrc/mixim/src/inet_stub/base/NotificationBoard.cc</li>
</ul>
</div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="a00164.html">NotificationBoard</a>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:32 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
